#ifndef _THREADLIBMUTEX_H
#define _THREADLIBMUTEX_H

#include "platform.h"

#if defined PLATFORM_WINDOWS
#include <windows.h>
#else
#include <pthread.h>
#endif

namespace ThreadLib
{
class Mutex
{
public:
    Mutex()
    {
#if defined PLATFORM_WINDOWS
        InitializeCriticalSection( &m_mutex );
#else
        pthread_mutex_init( &m_mutex, 0 );
#endif
    }

    ~Mutex()
    {
#if defined PLATFORM_WINDOWS
        DeleteCriticalSection( &m_mutex );
#else
        pthread_mutex_destroy( &m_mutex );
#endif
    }
    inline void lock()
    {
#if defined PLATFORM_WINDOWS
        EnterCriticalSection( &m_mutex );
#else
        pthread_mutex_lock( &m_mutex );
#endif
    }
    inline void unLock()
    {
#if defined PLATFORM_WINDOWS
        LeaveCriticalSection( &m_mutex );
#else
        pthread_mutex_unlock( &m_mutex );
#endif
    }

protected:
#if defined PLATFORM_WINDOWS
    CRITICAL_SECTION m_mutex;
#else
    pthread_mutex_t m_mutex;
#endif

};
}

#endif
